﻿using Core.Utils;
using Spine.Unity;
using UnityEngine;
namespace Core.Animation {
    /// <summary>
    /// 自制Animator
    /// </summary>
    public class Animator {
        private GameObject mObj;
        public Animator(GameObject obj) {
            mObj = obj;
            mState = new AnimationState(obj);
            UnityAnimation = mObj.GetComponent<UnityEngine.Animation>();
            SkeletonAnimation = mObj.GetComponent<SkeletonAnimation>();
        }

        public UnityEngine.Animation UnityAnimation  {
            get;
            private set;
        }

        public SkeletonAnimation SkeletonAnimation {
            get;
            private set;
        }

        private AnimationState mState;
        public AnimationProcess PlayAnim(string animName,bool isLoop) {
            if (mState == null) {
                mState = new AnimationState(mObj);
            }
            if (UnityAnimation != null) {
                return mState.SetAnimation(new CPUAnimation(UnityAnimation),animName,isLoop);
            }else if (SkeletonAnimation != null) {
                return mState.SetAnimation(new SpineAnimation(SkeletonAnimation),animName,isLoop);
            } else {
                return null;
            }
        }
    }
}